package com.sundaying.gooway.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;
import com.sundaying.gooway.entity.UrlClass;
import com.sundaying.gooway.service.UrlClassService;

public class UrlClassAction extends ActionSupport {
	private UrlClassService urlClassService;
	private List<UrlClass> urlClassList;
	private UrlClass urlClass;
	private int id;
	private List<Map<String, Object>> urlClassTree;

	// 将会被Struts2序列化为JSON字符串的对象
	private Map<String, Object> dataMap = new HashMap<String, Object>();
	// 视图datagrid属性
	private int page;
	private int rows;
	private long total;

	public UrlClassService getUrlClassService() {
		return urlClassService;
	}

	@Resource(name = "urlClassService")
	public void setUrlClassService(UrlClassService urlClassService) {
		this.urlClassService = urlClassService;
	}

	public List<UrlClass> getUrlClassList() {
		return urlClassList;
	}

	public void setUrlClassList(List<UrlClass> urlClassList) {
		this.urlClassList = urlClassList;
	}

	public UrlClass getUrlClass() {
		return urlClass;
	}

	public void setUrlClass(UrlClass urlClass) {
		this.urlClass = urlClass;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List<Map<String, Object>> getUrlClassTree() {
		return urlClassTree;
	}

	public void setUrlClassTree(List<Map<String, Object>> urlClassTree) {
		this.urlClassTree = urlClassTree;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public String add() {
		urlClassService.add(urlClass);
		return this.SUCCESS;
	}

	public String list() {
		urlClassList = urlClassService.list();
		return this.SUCCESS;
	}

	public String listByPage() {
		UrlClass urlClass = new UrlClass();
		urlClass.setId(id);
		urlClassList = urlClassService.list(page, rows, "", "" ,urlClass);
		total = urlClassService.total(urlClass);
		System.out.println(total);
		dataMap.clear();
		dataMap.put("total", total);
		dataMap.put("rows", urlClassList);
		return this.SUCCESS;
	}

	public String update() {
		urlClassService.update(urlClass);
		return this.SUCCESS;
	}

	public String delete() {
		urlClassService.delete(id);
		return this.SUCCESS;
	}

	public String tree() {
		urlClassTree = urlClassService.tree(0);
		return this.SUCCESS;
	}

}
